<template>
	<view class="user-order">
		<!-- header -->
		<view class="od-line2" @click="onNav2">
			<view :class="['item', swiperCurrent1 == item.id ? 'line2-active': ''] " :id="item.id" v-for="(item,index) in navList"
			 :key="index">
				{{item.name}}
			</view>
		</view>

		<swiper :duration="300" @change="changeSwiper" class="ud-swiper" :current="swiperCurrent1">
			<!-- 第一块轮播  全部 -->
			<swiper-item v-for="(row,sub) in 3" :key="sub">
				<!-- 可滚动区域 -->
				<scroll-view :scroll-y="true" class="scrollStyle">
					<view class="no-orderList" v-if="refundList.length==0">
						<text>暂无相关内容</text>
					</view>
					<view v-else class="content-box" v-for="(item,index) in refundList" :key="index">
						<view class="box-item">
							<view class="item1">
								<image class="title-name" :src="item.pro_img" mode="aspectFill"></image>
								<view class="item-box">
									<view class="item1-title">
										<text>{{item.pro_name}}</text>
										<!-- <view>
											<image :src="item.user_shavatar" mode="aspectFill" style="border-radius: 50%;"></image>
											<text>{{item.user_nickname}}</text>
										</view> -->
										<!-- <text class="iconfont enterShop">&#xe600;</text> -->
									</view>
									<view class="item1-name">
										<!-- <text>{{item.pro_name}}</text> -->
										<text>￥{{item.or_price}}</text>
										<text>x<text>{{item.or_pronum}}</text></text>
									</view>
									<view class="item-order">
										<text>订单号:{{item.order_no}}</text>
										<!-- <text>x<text>{{item.or_pronum}}</text></text> -->
									</view>
								</view>
							</view>
							<view class="item2">
								<view class="itme2-top">
									<text>退款说明:</text>
									<text>{{item.Refunds_stitle}}</text>
								</view>
								<view class="" v-if="sub == 0">
									<!-- <view class="textTips" v-if="item.Refunds_status == 3 || item.Refunds_status == 2 || item.Refunds_status == 4">
										<text>{{item.Refunds_status_name}}</text>
									</view> -->
									<view class="item2-btn" v-if="item.Refunds_status == 0 && item.Refunds_type == 1">
										<view class="btn1" @click="agreeOrrefuseGoods(item,3)">
											<text>同意退款</text>
										</view>
										<view class="btn1" @click="agreeOrrefuseGoods(item,4)">
											<text>拒绝退款</text>
										</view>
									</view>
									<view class="item2-btn" v-if="item.Refunds_status == 2 || item.Refunds_status == 5 || item.Refunds_status == 3 || item.Refunds_status == 1">
										<view class="">
											<text>{{item.Refunds_status_name}}</text>
										</view>
									</view>
									<view class="item2-btn" v-if="item.Refunds_status == 0 && item.Refunds_type == 2">
										<view class="btn1" @click="agreeOrrefuseGoods(item,1)">
											<text>同意退货</text>
										</view>
										<view class="btn1" @click="agreeOrrefuseGoods(item,2)">
											<text>拒绝退货</text>
										</view>
									</view>
									<view class="item2-btn" v-if="item.Refunds_status == 4">
										<view class="btn2" @click="agreeOrrefuseGoods(item,5)">
											<text>已收货并退款</text>
										</view>
										<view class="btn1" @click="agreeOrrefuseGoods(item,6)">
											<text>拒绝收货</text>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperCurrent1: 0,
				navList: [{
					id: '0',
					name: '全部'
				}, {
					id: '1',
					name: '已退款'
				}, {
					id: '2',
					name: '已拒绝'
				}],
				refundList: [],
				current_page: 1,
			}
		},
		onLoad() {
			this.getRefundList(1)
		},
		methods: {
			agreeOrrefuseGoods(item, index) {
				let tips = ""
				let type = ""
				if (index == 1) {
					tips = "确定同意退货？"
					type = "Agreed_Return"
				} else if (index == 2) {
					tips = "确定拒绝退货？"
					type = "Refuse_return"
				} else if (index == 3) {
					tips = "确定同意退款？"
					type = "refund"
				} else if (index == 4) {
					tips = "确定拒绝退款？"
					type = "Refusal_Refund"
				}else if (index == 5) {
					tips = "确定收到货并退款？"
					type = "Refuse_Reject"
				}else if(index == 6){
					tips = "确定拒接收货？"
					type = "Refusal_Refund"
				}
				uni.showModal({
					title: '提示',
					content: tips,
					success: res => {
						if (res.confirm) {
							this.confirmGoods(item.Refunds_id, type, index)
						} else if (res.cancel) {

						}
					}
				});
			},
			async confirmGoods(id, type, index) {
				uni.showLoading({
					title: '加载中'
				});
				let res = await this.$http.operatingRefunds({
					type: type,
					refunds_id: id
				});
				uni.hideLoading();
				console.log(res)
				if (res.code == 200) {
					if (index == 1 || index == 3) {
						this.swiperCurrent1 = 0
						this.getRefundList(1)
					} else if (index == 2) {
						this.swiperCurrent1 = 2
						this.getRefundList(3)
					} else if (index == 4) {
						this.swiperCurrent1 = 2
						this.getRefundList(3)
					}
					uni.showToast({
						title: res.message,
						icon: 'none',
						duration: 2000
					});

					// uni.navigateTo({
					// 	url:'/pages/afterSale/afterSale'
					// })
					// this.getRefundList()
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none',
						duration: 2000
					});
				}
			},
			async getRefundList(type) {
				let res = await this.$http.getRefunds({
					type: type,
					page: this.current_page
				});
				this.refundList = res.data
				// this.userOrder = res.data
				// if(this.userOrder.length == 0){
				// 	this.loadingText = ""
				// }
				// this.userOrder.forEach(item => {
				// 	let mun = Number(item.or_price)
				// 	item.totalNum = item.or_pronum * mun
				// 	item.status = this.$common.orderStatus(item.or_status)
				// })
			},
			onNav2(e) {
				this.swiperCurrent1 = e.target.id
				let num = Number(this.swiperCurrent1)
				this.getRefundList(num + 1)
			},
			changeSwiper(e) {
				this.swiperCurrent1 = e.target.current
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
				// 不需要判断登录
				// if (this.isLogin1) {

				// 	uni.navigateTo({
				// 		url: url
				// 	});
				// } else {
				// 	uni.showToast({
				// 		title: '请先登录',
				// 		icon: 'none'
				// 	});
				// 	setTimeout(() => {
				// 		uni.navigateTo({
				// 			url: '/pages/public/userLogin/userLogin'
				// 		});
				// 	}, 500)
				// }
			}
		},
	}
</script>

<style lang="scss" scoped>
	@import 'static/css/refund.scss';

	/* #ifdef MP-WEIXIN */
	.ud-swiper {
		height: 1140upx;

	}


	/* #endif */
</style>
